<?php
/**
* @package   auto_occasion
* @subpackage recherche
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class FoRechercheCtrl extends jController {
    /**
    *
    */
    function index() {


        $rep = $this->getResponse('htmlFo');
        $rep->menusActifs = frontHtmlResponse::MENU_RECHERCHE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_RECHERCHE) ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/recherche.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $rep->bodyTpl = 'recherche~FoRecherche';
        jClasses::inc('commun~common');


        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_RECHERCHE);
		$rep->title						= isset($headerContent->title)?$headerContent->title:'';
		$headerContent->title			= isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords		= isset($headerContent->keywords)? $headerContent->keywords:'' ;
		$headerContent->desc			= isset($headerContent->desc)? $headerContent->desc:'' ;
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;

        // enregistre les criteres si aucun résultat
        $critere = new stdClass();
        $critere->save = $this->intParam('saveCritere', 0);
        if ($critere->save == 1) {
            $critere->nom       = $this->stringParam('nom', '');
            $critere->prenom    = $this->stringParam('prenom', '');
            $critere->email     = $this->stringParam('email', '');
            //récupération des critère de recherche
            $temp = unserialize($_SESSION['SESS_ANNONCE_RESULT']);
            $critere->critere = $temp['query'];

            jClasses::inc('commun~acheteurCritereSrv');
            acheteurCritereSrv::ajouter($critere);
        }
         
               
        $rep->body->assignZone('oZoneRechercheLeft', 'recherche~FoRechercheLeft');
        $rep->body->assignZone('oZoneRechercheCenter', 'recherche~FoRechercheCenter');
        $rep->body->assignZone('oZoneRechercheRight', 'recherche~FoRechercheRight');

        // change le header de la page en cours
        //formatage des title,desc,keywords
        if(isset($_SESSION['SESS_ANNONCE_SEARCH'])){
            //parametre pour center
            $sessionCritere = unserialize($_SESSION['SESS_ANNONCE_SEARCH']);
            $marque         = new stdClass();
            $modele         = new stdClass();
            if(($sessionCritere->marqueId != 0) && ($sessionCritere->modeleId != 0)){
               
                $marque = common::chargeParId($sessionCritere->marqueId, 'ao_marque');
                $modele = common::chargeParId($sessionCritere->modeleId, 'ao_modele');
            } else {
                $marque->marque_libelle = $this->stringParam('lMarque');
                $modele->modele_libelle = $this->stringParam('lModele');
            }
            
            $categorie      = ($sessionCritere->cat) ? $sessionCritere->cat : '';
            $carburation    = ($sessionCritere->carbu) ? $sessionCritere->carbu : '';
            $nbPortes       = ($sessionCritere->porte) ? $sessionCritere->porte : '';
            $annees         = ($sessionCritere->annee) ? $sessionCritere->annee : '';
            $km             = ($sessionCritere->km) ? $sessionCritere->km : '';
            $vitesse        = ($sessionCritere->vitesse) ? $sessionCritere->vitesse : '';
            $localisation   = ($sessionCritere->localisation) ? $sessionCritere->localisation : '';
            $vendeur        = ($sessionCritere->vendeur) ? $sessionCritere->vendeur : '';
            $motcle         = ($sessionCritere->motcle) ? $sessionCritere->motcle : '';
            $image          = ($sessionCritere->image == 'on')      ? 'avec image'      : $sessionCritere->image;
            $video          = ($sessionCritere->video == 'on')      ? 'avec video'      : $sessionCritere->video;
            $main           = ($sessionCritere->main == 'on')       ? 'première main'   : $sessionCritere->main;
            $garantie       = ($sessionCritere->garantie == 'on')   ? 'avec garantie'   : $sessionCritere->garantie;
            $sessionCritere->version = ($sessionCritere->version) ? $sessionCritere->version : '';
            
            $headerContent->title = str_replace('{_MARQUE}',isset($marque->marque_libelle)?$marque->marque_libelle:"",$headerContent->title);
            $headerContent->title = str_replace('- {_MODELE}',isset($modele->modele_libelle)?$modele->modele_libelle:"",$headerContent->title);
            $headerContent->title = str_replace('- {_VERSION}',isset($sessionCritere->version)?$sessionCritere->version:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_CAT}',isset($categorie)?$categorie:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_CARBU}',isset($carburation)?$carburation:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_NB_PORTES}',isset($nbPortes)?$nbPortes:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_ANNEE}',isset($annees)?$annees:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_KM}',isset($km)?$km:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_VITESSE}',isset($vitesse)?$vitesse:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_LOCALISATION}',isset($localisation)?$localisation:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_VENDEUR}',isset($vendeur)?$vendeur:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_IMAGE}',isset($image)?$image:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_VIDEO}',isset($video)?$video:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_MAIN}',isset($main)?$main:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_GARANTIE}',isset($garantie)?$garantie:"",$headerContent->title);
            $headerContent->title  = str_replace('- {_PRIX}',$this->stringParam('region', ''),$headerContent->title);
            $headerContent->title  = str_replace('- {_REGION}',$this->stringParam('prix', ''),$headerContent->title);
            
            $headerContent->keywords  = str_replace('{_MOTCLE}',isset($motcle)?$motcle:"",$headerContent->keywords);

            $marque->marque_libelle = ($marque->marque_libelle) ? $marque->marque_libelle : "";
            $modele->modele_libelle = ($modele->modele_libelle) ? $modele->modele_libelle : "";

			$headerContent->desc = str_replace('{_MARQUE}',isset($marque->marque_libelle)?$marque->marque_libelle:"",$headerContent->desc);
            $headerContent->desc = str_replace('- {_MODELE}',isset($modele->modele_libelle)?$modele->modele_libelle:"",$headerContent->desc);
            $headerContent->desc = str_replace('- {_VERSION}',isset($sessionCritere->version)?$sessionCritere->version:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_CAT}',isset($categorie)?$categorie:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_CARBU}',isset($carburation)?$carburation:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_NB_PORTES}',isset($nbPortes)?$nbPortes:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_ANNEE}',isset($annees)?$annees:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_KM}',isset($km)?$km:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_VITESSE}',isset($vitesse)?$vitesse:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_LOCALISATION}',isset($localisation)?$localisation:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_VENDEUR}',isset($vendeur)?$vendeur:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_IMAGE}',isset($image)?$image:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_VIDEO}',isset($video)?$video:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_MAIN}',isset($main)?$main:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_GARANTIE}',isset($garantie)?$garantie:"",$headerContent->desc);
            $headerContent->desc  = str_replace('- {_PRIX}',$this->stringParam('region', ''),$headerContent->desc);
            $headerContent->desc  = str_replace('- {_REGION}',$this->stringParam('prix', ''),$headerContent->desc);
            
        }
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;
        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);
        
        //pubHidden et rightContent
        $paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
        $rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
        

        $rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent');
        //---
        
        return $rep;
    }


     /**
     * Récupère l'url de redirection pour les tag cloud
     */
    function geturlCloud () {
        $rep = $this->getResponse('json') ;

        $motcle = $this->stringParam('motcle') ;
        
        $rep->data = jUrl::get('recherche~FoRecherche:index', array('motcle'=>$motcle));

        return $rep;
    }
    
    /*
     * Fonction recherche d'annonce par marque
     * 
     */
    function rechercheParMarque(){

        jClasses::inc('commun~common');
        jClasses::inc('marqueModele~marqueSrv');

        $rep = $this->getResponse('htmlFo');
        $rep->menusActifs = frontHtmlResponse::MENU_RECHERCHE_PAR_MARQUE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_RECHERCHE_PAR_MARQUE) ;
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/css/sliderkit.css');
        
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/carousel_custom.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.idTabs.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.easing.1.3.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.sliderkit.1.9.1.pack.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/essai.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $rep->bodyTpl = 'recherche~FoRechercheParMarque';

        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_RECHERCHE_MARQUE);
        // change le header de la page en cours
		$rep->title						= isset($headerContent->title)?$headerContent->title:'';
		$headerContent->title			= isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords		= isset($headerContent->keywords)? $headerContent->keywords:'' ;
		$headerContent->desc			= isset($headerContent->desc)? $headerContent->desc:'' ;
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;

        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);

        $listeMarque = marqueSrv::getAllMarque(true);
        $rep->body->assign('marque', $listeMarque);
        //pubHidden et rightContent
        $paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
        $rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
        
        $paramRight = array('ad'=>1,'no_need_cc2'=>1);
        $rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent',$paramRight);
        //---
        return $rep;
    }

        /*
     * Fonction recherche d'annonce par catégories
     * 
     */
    function rechercheParCategorie(){

        jClasses::inc('commun~common');
        jClasses::inc('essais~essaisSrv');

        $rep = $this->getResponse('htmlFo');
        $rep->menusActifs = frontHtmlResponse::MENU_RECHERCHE_PAR_CATEGORIE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_RECHERCHE_PAR_CATEGORIE) ;
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/css/sliderkit.css');
        
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/carousel_custom.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.idTabs.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.easing.1.3.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.sliderkit.1.9.1.pack.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/essai.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $rep->bodyTpl = 'recherche~FoRechercheParCategorie'; 
        
        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_RECHERCHE_CATEGORIE);
        // change le header de la page en cours
        $rep->title				= isset($headerContent->title)?$headerContent->title:'';
		$headerContent->title			= isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords		= isset($headerContent->keywords)? $headerContent->keywords:'' ;
		$headerContent->desc			= isset($headerContent->desc)? $headerContent->desc:'' ;
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;

        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);

        $categorie       = essaisSrv::getAllCatVoiture() ;
        $rep->body->assign('categorie', $categorie);
        //pubHidden et rightContent
        $paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
        $rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
        
        $paramRight = array('ad'=>1,'no_need_cc2'=>1);
        $rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent',$paramRight);
        //---
        return $rep;
    }
    
    /*
     * Page de recherche
     */
    function rechercheOccasion(){
        
        jClasses::inc('commun~common');
		jClasses::inc('commun~departementSrv');
		jClasses::inc('marqueModele~marqueSrv');

        $marque = marqueSrv::getAllMarque(true); // order by marque_ordre
        $region = departementSrv::getAllRegion();
        
        
        
        $rep = $this->getResponse('htmlFo');
        
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/css/sliderkit.css');
        
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/carousel_custom.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.idTabs.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.easing.1.3.min.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/jquery.sliderkit.1.9.1.pack.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/essai.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');
        
        $rep->menusActifs = frontHtmlResponse::MENU_RECHERCHE_PAR_MARQUE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_RECHERCHE_PAR_MARQUE) ;

        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_RECHERCHE_OCCASION);
        // change le header de la page en cours
		$rep->title				= isset($headerContent->title)?$headerContent->title:'';
		$headerContent->title			= isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords		= isset($headerContent->keywords)? $headerContent->keywords:'' ;
		$headerContent->desc			= isset($headerContent->desc)? $headerContent->desc:'' ;
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;
        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);

        $rep->bodyTpl = 'recherche~FoRechercheOccasion';

        jClasses::inc('commun~common');
        
        
        $rep->body->assign('marque', $marque);		
        $rep->body->assign('region', $region);
        
        //pubHidden et rightContent
        $paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
        $rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
        
        $paramRight = array('ad'=>1,'no_need_cc2'=>1);
        $rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent',$paramRight);
        //---
        
        return $rep;
    }
}

